package com.loadburn.heron.config;

import org.apache.commons.io.FilenameUtils;

/**
 * @author slacrey (scstlinfeng@yahoo.com)
 *         Date: 13-12-23
 */
public class GlobalConfig {

    private static final String PROPERTIES_CONFIG = "classpath:application.properties";
    private static final String ADMIN_PATH = "adminPath";
    private static final String FRONT_PATH = "frontPath";
    private static final String URL_SUFFIX = "urlSuffix";
    private static final String STORAGE_CONFIG = "storage.config";
    private static final String EMAIL_CONFIG = "email.config";
    private static final String SECURITY_CONFIG = "security.config";
    private static final String CAPTCHA_CONFIG = "captcha.config";
    private static final String WEB_CACHE_CONFIG = "web.cache.config";
    private static final String WEB_VIEW_PREFIX = "web.view.prefix";
    private static final String WEB_VIEW_SUFFIX = "web.view.suffix";
    private static String WEB_VIEW_PREFIX_VALUE;

    /**
     * 属性文件加载对象
     */
    private static PropertiesLoader propertiesLoader;

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        if (propertiesLoader == null) {
            propertiesLoader = new PropertiesLoader(PROPERTIES_CONFIG);
        }
        return propertiesLoader.getProperty(key);
    }

    //=========================================================

    public static String getAdminPath() {
        return getConfig(ADMIN_PATH);
    }

    public static String getFrontPath() {
        return getConfig(FRONT_PATH);
    }

    public static String getUrlSuffix() {
        return getConfig(URL_SUFFIX);
    }

    public static String getStorageConfig() {
        return getConfig(STORAGE_CONFIG);
    }

    public static String getEmailConfig() {
        return getConfig(EMAIL_CONFIG);
    }

    public static String getShiroConfig() {
        return getConfig(SECURITY_CONFIG);
    }

    public static String getCaptchaConfig() {
        return getConfig(CAPTCHA_CONFIG);
    }

    public static String getWebCacheConfig() {
        return getConfig(WEB_CACHE_CONFIG);
    }

    public static String getWebViewPrefix() {
        if (WEB_VIEW_PREFIX_VALUE == null) {
            WEB_VIEW_PREFIX_VALUE = FilenameUtils.normalizeNoEndSeparator(getConfig(WEB_VIEW_PREFIX), true);
        }
        return WEB_VIEW_PREFIX_VALUE;
    }

    public static String getWebViewSuffix() {
        return getConfig(WEB_VIEW_SUFFIX);
    }

}
